/*================================================================
*   Copyright (C) 2019 Guangzhou Firefly Ltd. All rights reserved.
*   
*   文件名称：pm25_th.c
*   创 建 者：luhuadong
*   创建日期：2019年09月03日
*   描    述：
*
================================================================*/


#include <rtthread.h>
#include <rtdevice.h>
#include "pm25.h"

/* Arduino A3 --> PB0 */
/* Arduino A1 --> PA1 */
#define GP2Y_DATA_PIN    GET_PIN(A, 1)  

static void pm25_entry(void *parameter)
{
    float pm25_value_f;
    int   pm25_value_i;
    while (1)
    {
        pm25_value_f = gp2y_read_pm25();
        pm25_value_i = (int)(pm25_value_f);      
        rt_kprintf("pm25: %d mg/m3\n",pm25_value_i);
        rt_thread_mdelay(2000);
    }
}


int pm25_init(void)
{
    rt_thread_t pm25_thread;

    gp2y_hw_init();

    pm25_thread = rt_thread_create("gp2y_pm2", pm25_entry, RT_NULL,
                                    1024, RT_THREAD_PRIORITY_MAX / 2 - 1, 20);
    if (pm25_thread != RT_NULL) {
        
        rt_thread_startup(pm25_thread);
    }

    return RT_EOK;
}
//INIT_APP_EXPORT(pm25_init);
MSH_CMD_EXPORT(pm25_init, GP2Y PM2.5 sensor thread);
